<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>增强版音乐频谱分析器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            color: white;
        }

        .container {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 2rem;
            box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
            border: 1px solid rgba(255, 255, 255, 0.18);
            width: 90%;
            max-width: 900px;
        }

        h1 {
            text-align: center;
            margin-bottom: 2rem;
            font-size: 2.5rem;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }

        .mode-selector {
            display: flex;
            justify-content: center;
            gap: 1rem;
            margin-bottom: 2rem;
            flex-wrap: wrap;
        }

        .mode-btn {
            background: linear-gradient(45deg, #667eea, #764ba2);
            border: none;
            color: white;
            padding: 0.8rem 1.5rem;
            border-radius: 8px;
            cursor: pointer;
            font-size: 1rem;
            transition: all 0.2s;
            opacity: 0.7;
        }

        .mode-btn.active {
            opacity: 1;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }

        .input-section {
            margin-bottom: 2rem;
        }

        .input-group {
            margin-bottom: 1.5rem;
        }

        .input-group label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: bold;
        }

        .input-group input {
            width: 100%;
            padding: 0.8rem;
            border: none;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.9);
            color: #333;
        }

        .file-input-wrapper {
            position: relative;
            display: inline-block;
            cursor: pointer;
            background: linear-gradient(45deg, #667eea, #764ba2);
            border-radius: 10px;
            padding: 1rem 2rem;
            transition: transform 0.2s, box-shadow 0.2s;
            width: 100%;
            text-align: center;
        }

        .file-input-wrapper:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }

        .file-input {
            position: absolute;
            opacity: 0;
            width: 100%;
            height: 100%;
            cursor: pointer;
        }

        .control-panel {
            display: flex;
            justify-content: center;
            gap: 1rem;
            margin-bottom: 2rem;
            flex-wrap: wrap;
        }

        .btn {
            background: linear-gradient(45deg, #667eea, #764ba2);
            border: none;
            color: white;
            padding: 0.8rem 1.5rem;
            border-radius: 8px;
            cursor: pointer;
            font-size: 1rem;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }

        .btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        .visualizer-container {
            margin-bottom: 2rem;
            border-radius: 15px;
            overflow: hidden;
            background: rgba(0, 0, 0, 0.3);
            padding: 1rem;
        }

        #canvas {
            width: 100%;
            height: 300px;
            border-radius: 10px;
            background: rgba(0, 0, 0, 0.5);
        }

        .progress-container {
            margin-top: 1rem;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            height: 8px;
            overflow: hidden;
        }

        .progress-bar {
            height: 100%;
            background: linear-gradient(90deg, #667eea, #764ba2);
            width: 0%;
            transition: width 0.1s linear;
        }

        .info-panel {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            padding: 1rem;
            margin-top: 1rem;
        }

        .performance-settings {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 10px;
            padding: 1rem;
            margin-bottom: 1rem;
        }

        .setting-group {
            display: flex;
            align-items: center;
            gap: 1rem;
            margin-bottom: 0.5rem;
        }

        .setting-group select {
            padding: 0.5rem;
            border: none;
            border-radius: 5px;
            background: rgba(255, 255, 255, 0.9);
            color: #333;
        }

        .hidden {
            display: none;
        }

        .loading {
            text-align: center;
            font-size: 1.2rem;
            color: #ffd700;
        }

        .error {
            text-align: center;
            color: #ff6b6b;
            background: rgba(255, 107, 107, 0.1);
            padding: 1rem;
            border-radius: 8px;
            margin: 1rem 0;
        }

        .success {
            text-align: center;
            color: #4caf50;
            background: rgba(76, 175, 80, 0.1);
            padding: 1rem;
            border-radius: 8px;
            margin: 1rem 0;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🎵 增强版音乐频谱分析器</h1>
        
        <!-- 模式选择 -->
        <div class="mode-selector">
            <button id="localMode" class="mode-btn active">📁 本地文件</button>
            <button id="streamMode" class="mode-btn">🌐 网络流媒体</button>
            <button id="externalMode" class="mode-btn">📊 外部频谱文件</button>
        </div>

        <!-- 输入区域 -->
        <div class="input-section">
            <!-- 本地文件模式 -->
            <div id="localInputs" class="input-mode">
                <div class="input-group">
                    <label>选择音频文件：</label>
                    <div class="file-input-wrapper">
                        <input type="file" id="audioFile" class="file-input" accept="audio/*">
                        <span>📁 选择音频文件</span>
                    </div>
                </div>
            </div>

            <!-- 网络流媒体模式 -->
            <div id="streamInputs" class="input-mode hidden">
                <div class="input-group">
                    <label>音频流URL：</label>
                    <input type="url" id="streamUrl" placeholder="https://example.com/stream.mp3">
                </div>
                <div class="input-group">
                    <label>频谱文件URL（可选）：</label>
                    <input type="url" id="spectrumUrl" placeholder="https://example.com/spectrum.bin">
                </div>
            </div>

            <!-- 外部频谱文件模式 -->
            <div id="externalInputs" class="input-mode hidden">
                <div class="input-group">
                    <label>音频文件：</label>
                    <div class="file-input-wrapper">
                        <input type="file" id="audioFileExt" class="file-input" accept="audio/*">
                        <span>📁 选择音频文件</span>
                    </div>
                </div>
                <div class="input-group">
                    <label>频谱文件：</label>
                    <div class="file-input-wrapper">
                        <input type="file" id="spectrumFile" class="file-input" accept=".json,.bin,.spectrum">
                        <span>📊 选择频谱文件</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- 性能设置 -->
        <div class="performance-settings">
            <h3>⚙️ 性能设置</h3>
            <div class="setting-group">
                <label>质量等级：</label>
                <select id="qualityLevel">
                    <option value="low">低 (20fps, 1024 FFT)</option>
                    <option value="medium" selected>中 (43fps, 2048 FFT)</option>
                    <option value="high">高 (60fps, 4096 FFT)</option>
                </select>
            </div>
            <div class="setting-group">
                <label>压缩格式：</label>
                <select id="compressionType">
                    <option value="none">无压缩</option>
                    <option value="rle" selected>RLE压缩</option>
                    <option value="deflate">Deflate压缩</option>
                </select>
            </div>
            <div class="setting-group">
                <label>使用Web Worker：</label>
                <select id="useWebWorker">
                    <option value="true" selected>是</option>
                    <option value="false">否</option>
                </select>
            </div>
        </div>

        <!-- 控制面板 -->
        <div class="control-panel">
            <button id="loadBtn" class="btn">📥 加载</button>
            <button id="playBtn" class="btn" disabled>▶️ 播放</button>
            <button id="pauseBtn" class="btn" disabled>⏸️ 暂停</button>
            <button id="stopBtn" class="btn" disabled>⏹️ 停止</button>
            <button id="analyzeBtn" class="btn" disabled>🔬 分析频谱</button>
            <button id="exportBtn" class="btn" disabled>💾 导出频谱</button>
        </div>

        <!-- 可视化区域 -->
        <div class="visualizer-container">
            <canvas id="canvas"></canvas>
            <div class="progress-container">
                <div class="progress-bar" id="progressBar"></div>
            </div>
        </div>

        <!-- 信息面板 -->
        <div class="info-panel">
            <div id="status">请选择模式和音频来源...</div>
            <div id="fileInfo"></div>
            <div id="performanceInfo"></div>
        </div>
    </div>

    <script src="streaming-analyzer.js"></script>
    <script src="enhanced-script.js"></script>
</body>
</html>
